package com.fulu.game.bi.controller.dispatch;

import com.fulu.game.bi.entity.dto.ExposureRoomListDTO;
import com.fulu.game.bi.entity.vo.Result;
import com.fulu.game.bi.entity.vo.common.NameMsgVO;
import com.fulu.game.bi.service.impl.dispatch.RoomExposureStatServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 聊天室曝光总览
 */
@RequestMapping("/api/v1/exposure/room")
@RestController
public class RoomExposureStatController {

    @Autowired
    private RoomExposureStatServiceImpl roomExposureStatService;

    /**
     * 聊天室曝光总览-实时数据
     */
    @PostMapping("/realtime")
    public Result realtime() {
        return Result.success().data(roomExposureStatService.realtime());
    }

    /**
     * 聊天室曝光总览-列表
     */
    @PostMapping("/list")
    public Result list(ExposureRoomListDTO dto) {
        return Result.success().data(roomExposureStatService.list(dto));
    }

    /**
     * 聊天室曝光总览-导出
     */
    @PostMapping("/export")
    public void export(ExposureRoomListDTO dto) {
        roomExposureStatService.export(dto);
    }

    /**
     * 聊天室曝光总览-折线图
     */
    @PostMapping("/line-chart")
    public Result lineChart() {
        Map<String, String> cacheMap = new LinkedHashMap<>();
        cacheMap.put("曝光人数", "exposureUserNum");
        cacheMap.put("曝光次数", "exposureNum");
        cacheMap.put("进厅人数", "roomEnterUserNum");
        cacheMap.put("进厅次数", "roomEnterNum");
        cacheMap.put("CTR", "ctr");
        cacheMap.put("钻石消费人数", "virtualMoneyUserNum");
        cacheMap.put("钻石消费次数", "virtualMoneyNum");
        cacheMap.put("钻石CVR", "virtualCvr");
        cacheMap.put("皮皮币消费人数", "pipiMoneyUserNum");
        cacheMap.put("皮皮币消费次数", "pipiMoneyNum");
        cacheMap.put("皮皮币CVR", "pipiMoneyCvr");

        List<NameMsgVO> list = cacheMap.entrySet().stream()
                .map(entry -> {
                    NameMsgVO idNameVO = new NameMsgVO();
                    idNameVO.setName(entry.getValue());
                    idNameVO.setMsg(entry.getKey());
                    if (entry.getValue().toLowerCase(Locale.getDefault()).contains("ctr") || entry.getValue().toLowerCase(Locale.getDefault()).contains("cvr")) {
                        idNameVO.setType("percent");
                    }
                    return idNameVO;
                })
                .collect(Collectors.toList());
        return Result.success().data(list).msg("获取成功");
    }
}
